<?php
/**
 * Created by PhpStorm.
 * User: dolia
 * Date: 2016/4/11
 * Time: 17:29
 */

namespace App\Http\Controllers\Api\V1;


use App\Exceptions\Api\ApiDoneErrorException;
use App\Exceptions\Api\ApiInputErrorException;
use App\Exceptions\Api\ApiRsaEecryptErrorException;
use App\Exceptions\Api\ApiUserNotLoginErrorException;
use App\Exceptions\Api\ApiValidateErrorException;
use App\Http\Controllers\Controller;
use App\Interfaces\BrandService;

class BrandController extends Controller{

    /**
     * @api {post} /brand/cat_recommend_brand/{cat_id} 获取分类下的推荐品牌
     * @apiName Brand/getCatRecommendBrands
     * @apiGroup Brand
     * @apiDescription 获取分类下的推荐品牌
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
    [
        {
        "brand_id": 99,
        "brand_name": "发希 Fascy",
        "brand_logo": "29adcce3c04662ff3dd4ca63683787d4",
        "m_brand_logo": "44b7e7a156f86c84e7b50b76a29fd670",
        "brand_desc": "韩国护肤彩妆品牌",
        "sort_order": 50,
        "is_recommend": 0,
        "cat_id": 388,
        "mobile_brand_logo": "http://afutest.img-cn-qingdao.aliyuncs.com/44b7e7a156f86c84e7b50b76a29fd670.png"
        }
    ]
     * @apiErrorExample Error-Response 01:
     * HTTP/1.1 400 Bad Request
    {
    "message": "缺少请求参数cat_id"
    }
     * @apiErrorExample Error-Response 02:
     * HTTP/1.1 202 Accepted
    {
    "message": "该分类下没有推荐品牌"
    }
     */

    public function getCatRecommendBrands($cat_id,BrandService $brandService){
        if(empty($cat_id)){
            throw new ApiInputErrorException('缺少请求参数cat_id');
        }
        $brands = $brandService->getCatRecommendBrands($cat_id);
        if($brands){
            return response()->json($brands);
        }else{
            throw new ApiDoneErrorException('该分类下没有推荐品牌');
        }
    }

} 